package com.tz.dream.architect.mvp.list.demo;

import android.content.Context;

import com.tz.dream.architect.mvp.list.base.BaseModel;
import com.tz.dream.architect.mvp.list.demo.bean.PostModel;
import com.tz.dream.architect.mvp.utils.HttpUtils;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 作者: Dream on 16/9/24 21:09
 * QQ:510278658
 * E-mail:510278658@qq.com
 */
public class MyListModel extends BaseModel {

    public MyListModel(Context context) {
        super(context);
    }

    //获取精华列表
    public void getEssenceList(int page, int type,final HttpUtils.OnLceHttpResultListener onLceHttpResultListener) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(getServerUrl())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create()).build();

        IEssenceService essenceService = retrofit.create(IEssenceService.class);
        essenceService.getLceEssenseList(page,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PostModel>() {
            @Override
            public void onCompleted() {
                onLceHttpResultListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                onLceHttpResultListener.onError(new Exception(e));
            }

            @Override
            public void onNext(PostModel model) {
                onLceHttpResultListener.onResult(model);
            }

        });
    }

}
